package com.goa.controller;

import com.goa.dto.Params;
import com.goa.service.SmartBiService;
import com.goa.vo.AjaxResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author chuyongshuo
 * @version 1.0
 * @date 2024/11/8 8:15
 */
@RestController
@RequestMapping("/smartBi")
@CrossOrigin
public class SmartBiController {

    private static final Logger logger = LoggerFactory.getLogger(SmartBiController.class);

    @Autowired
    SmartBiService smartBiService;

    //127.0.01:8888/smartBi/getDeviceInfoById?deviceId=1
    @GetMapping(value = "/getDeviceInfoById",name = "查询设备信息")
    public AjaxResult getDeviceInfoById(@RequestParam String deviceId){
       logger.info("进入查询设备接口,设备id是{}",deviceId);
       if (deviceId==null||"".equals(deviceId)){
           return AjaxResult.error("设备ID为空");//500
       }
      return smartBiService.getDeviceInfoById(deviceId);
    }

    //127.0.01:8888/smartBi/getDeviceStateSlicing
    @PostMapping(value = "/getDeviceStateSlicing",name = "设备状态时间切片")
    public AjaxResult getDeviceStateSlicing(@RequestBody Params params)  {
        logger.info("进入查询电流电压涉折线图接口,参数是{}",params);
        String deviceId = params.getDeviceId();
        String dateType = params.getDateType();
        String dateTime = params.getDateTime();
        if (deviceId==null||"".equals(deviceId)){
            return AjaxResult.error("暂无设备信息");
        }
        return  smartBiService.getDeviceStateSlicing(deviceId,dateType,dateTime);
    }

    //127.0.01:8888/smartBi/plotCurrentVoltageGraph
    @PostMapping(value = "/plotCurrentVoltageGraph",name = "电流电压折线图")
    public AjaxResult plotCurrentVoltageGraph(@RequestBody Params params)  {
        logger.info("进入查询电流电压涉折线图接口,参数是{}",params);
        String deviceId = params.getDeviceId();
        String dateType = params.getDateType();
        String dateTime = params.getDateTime();
        if (deviceId==null||"".equals(deviceId)){
            return AjaxResult.error("暂无设备信息");
        }
//        return  smartBiService.plotCurrentVoltageGraph(deviceId,dateType,dateTime);
        return null;
    }
    @PostMapping(value = "/getEnergyConsumption",name = "获取能耗折线图")
    public  AjaxResult getEnergyConsumption(@RequestBody Params params){
        logger.info("获取能耗折线图,参数是{}",params);
        String deviceId = params.getDeviceId();
        String dateType = params.getDateType();
        String dateTime = params.getDateTime();
        if (deviceId==null||"".equals(deviceId)){
            return AjaxResult.error("暂无设备信息");
        }
        return smartBiService.getEnergyConsumption(deviceId,dateType,dateTime);
    }

}
